$(document).ready(function(){
    $('#loginForm').bind('submit', function(){
    	if($("#j_username").val() == "") {
			$("#msgShow").html("用户名不能为空，请输入用户名");
			return false;
    	}
    	if($("#j_password").val() == "") {
			$("#msgShow").html("密码不能为空，请输入密码");
			return false;
    	}
    	$.ajax({
    		url: basePath + "/auth/loginReq",
    		type: 'POST',
    		dataType : "json",
    		data: $('#loginForm').serialize(),
    		success: function(data) {
    			if (data.code != "000") {
    				$("#msgShow").html(data.msg);
    				clear();
    			} else {
    				window.location.href = basePath + "/auth/main";
    			}
    		},
    		error: function(data) {
    			$("#msgShow").html("系统异常,请联系管理员");
    		}
    	});
    	return false;
    });
});

function clear(){
	$("#userName").val(null);
	$("#password").val(null);
}

function getFormJson(frm) {
	var o = {};
	var a = $(frm).serializeArray();
	$.each(a, function () {
		if (o[this.name] !== undefined) {
			if (!o[this.name].push) {
				o[this.name] = [o[this.name]];
			}
			o[this.name].push(this.value || '');
		} else {
			o[this.name] = this.value || '';
		}
	});

	return o;
}
